package org.bulldog.playlist.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;

/**
 * Created by zhanghongbin on 2017/9/7.
 *
 * @author zhanghongbin
 * @version 1.0
 */
public final class ThreadUtil {

    private static ExecutorService executorService;

    static {
        executorService = java.util.concurrent.Executors.newCachedThreadPool(new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r,"thread-playlist");
                thread.setDaemon(true);
                return thread;
            }
        });
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                executorService.shutdown();
            }
        },"thread-playlist-shutdown"));
    }

    private ThreadUtil() {

    }


    public static void execute(Runnable runnable) {
        executorService.execute(runnable);
    }
}
